<template>
    <div class="batchAppraisal">
      <el-form :model="ruleForm"
               ref="ruleForm"
               label-width="130px"
               class="yuyi-ruleForm">
        <el-form-item label="鉴定结果" prop="name">
          <el-select size="small" v-model="ruleForm.mdCode" placeholder="请选择类型">
            <el-option label="销毁" value="0"></el-option>
            <el-option label="不销毁" value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="鉴定理由" prop="name" v-if="ruleForm.mdCode === '1'">
          <el-input  type="textarea"
                     size="small"
                     show-word-limit
                     maxlength="200"
                     :autosize="autosize"
                     v-model="ruleForm.newVal"></el-input>
        </el-form-item>
        <!--<el-form-item label="延期日期" prop="name" v-if="ruleForm.mdCode === '2'">
          <el-input  type="tel"
                     size="small"
                     maxlength="8"
                     v-model="ruleForm.newVal"></el-input>
        </el-form-item>-->

        <el-form-item label="">
          <el-button size="small" :loading="subLoading" type="primary" @click="submitForm('ruleForm')">提交</el-button>
          <el-button size="small" :loading="subLoading" @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>

      </el-form>
    </div>
</template>

<script>
import { requestDestroyBatch } from '../../../../../api/appraisal'

export default {
  name: 'batchAppraisal',
  props: {
    changesData: {
      type: Array,
      default: () => ([])
    },
    idCategory: {
      default: ''
    }
  },
  data () {
    return {
      autosize: {
        minRows: 6,
        maxRows: 8
      },
      ruleForm: {
        mdCode: '0',
        newVal: ''
      },
      subLoading: false
    }
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.subLoading = true
          this.ruleForm.ids = []
          this.changesData.map(item => {
            this.ruleForm.ids.push(item.id)
          })
          requestDestroyBatch(this.ruleForm, { idCategory: this.idCategory }).then(res => {
            // console.log(res.data)
            this.$message.success('操作成功！')
            this.$emit('handleSuccess')
            this.subLoading = false
          }).catch(() => {
            this.subLoading = false
          })
        } else {
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style lang="scss" scoped>
.batchAppraisal{
  height: 100%;
  .yuyi-ruleForm{
    padding-right: 80px;
    ::v-deep .el-select{
      width: 100%;
    }
  }
}
</style>
